Option Explicit On Option Strict On ' to illustrate parallel arrays Public Class Form1 Inherits System.Windows.Forms.Form Dim numbers(200) As Integer Dim values(200) As String Dim numItems As Integer #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents LstInfo As System.Windows.Forms.ListBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents TxtLookup As System.Windows.Forms.TextBox Friend WithEvents BtnLook As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents TxtFound As System.Windows.Forms.TextBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents BtnClassLookup As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.LstInfo = New System.Windows.Forms.ListBox Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.TxtLookup = New System.Windows.Forms.TextBox Me.BtnLook = New System.Windows.Forms.Button Me.BtnQuit = New System.Windows.Forms.Button Me.TxtFound = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.BtnClassLookup = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(227, 35) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(155, 31) Me.Label1.TabIndex = 0 Me.Label1.Text = "Look Up Key" ' 'LstInfo ' Me.LstInfo.Location = New System.Drawing.Point(40, 132) Me.LstInfo.Name = "LstInfo" Me.LstInfo.Size = New System.Drawing.Size(180, 251) Me.LstInfo.TabIndex = 1 ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(33, 90) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(187, 28) Me.Label2.TabIndex = 2 Me.Label2.Text = "All Info" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(293, 132) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(120, 21) Me.Label3.TabIndex = 3 Me.Label3.Text = "Look Up:" ' 'TxtLookup ' Me.TxtLookup.Location = New System.Drawing.Point(433, 132) Me.TxtLookup.Name = "TxtLookup" Me.TxtLookup.Size = New System.Drawing.Size(87, 20) Me.TxtLookup.TabIndex = 4 Me.TxtLookup.Text = "" ' 'BtnLook ' Me.BtnLook.Location = New System.Drawing.Point(300, 180) Me.BtnLook.Name = "BtnLook" Me.BtnLook.Size = New System.Drawing.Size(107, 35) Me.BtnLook.TabIndex = 5 Me.BtnLook.Text = "Look Up" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(433, 180) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(107, 35) Me.BtnQuit.TabIndex = 6 Me.BtnQuit.Text = "Quit" ' 'TxtFound ' Me.TxtFound.Location = New System.Drawing.Point(440, 257) Me.TxtFound.Name = "TxtFound" Me.TxtFound.ReadOnly = True Me.TxtFound.Size = New System.Drawing.Size(173, 20) Me.TxtFound.TabIndex = 8 Me.TxtFound.Text = "" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(300, 257) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(120, 20) Me.Label4.TabIndex = 7 Me.Label4.Text = "Found" ' 'BtnClassLookup ' Me.BtnClassLookup.Location = New System.Drawing.Point(264, 80) Me.BtnClassLookup.Name = "BtnClassLookup" Me.BtnClassLookup.Size = New System.Drawing.Size(112, 40) Me.BtnClassLookup.TabIndex = 9 Me.BtnClassLookup.Text = "LookUpClass" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(639, 464) Me.Controls.Add(Me.BtnClassLookup) Me.Controls.Add(Me.TxtFound) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.BtnQuit) Me.Controls.Add(Me.BtnLook) Me.Controls.Add(Me.TxtLookup) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.LstInfo) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim inpf As IO.StreamReader If IO.File.Exists("info.txt") Then inpf = IO.File.OpenText("info.txt") Do While inpf.Peek <> -1 And numItems <= 200 Dim curr As Integer Dim currStr As String Dim currLine As String Dim currVal As String currLine = inpf.ReadLine() Dim commapos As Integer commapos = currLine.IndexOf(",") currStr = currLine.Substring(0, commapos) curr = Convert.ToInt32(currStr) numbers(numItems) = curr currVal = currLine.Substring(commapos + 1) values(numItems) = currVal numItems = numItems + 1 LstInfo.Items.Add(currLine) Loop End If End Sub Private Sub BtnLook_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLook.Click Dim lookup As Double Dim value As String Dim found As Boolean = False If IsNumeric(TxtLookup.Text) Then lookup = Convert.ToDouble(TxtLookup.Text) Dim cnt As Integer For cnt = 0 To numItems If numbers(cnt) = lookup Then TxtFound.Text = values(cnt) found = True End If Next If Not found Then TxtFound.Text = "" MsgBox("That number is not found") End If Else MsgBox("look up value must be numeric") End If End Sub Private Sub BtnClassLookup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClassLookup.Click Dim toLookup As Integer Dim movieName As String Dim cnt As Integer Dim whereFound As Integer = Nothing If IsNumeric(TxtLookup.Text) Then toLookup = Convert.ToInt32(TxtLookup.Text) For cnt = 0 To numItems - 1 If toLookup = numbers(cnt) Then ' found the number whereFound = cnt End If Next cnt If whereFound = Nothing Then MsgBox("I'm sorry, that movie is not found") Else ' found movieName = values(whereFound) TxtFound.Text = movieName End If Else MsgBox("movie number to lookup needs to be a number") End If End Sub End Class